//
//  AnimationViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2017/2/15.
//  Copyright © 2017年 WanJiading. All rights reserved.
//

import UIKit

class AnimationViewController: UIViewController {

	var imageView: UIImageView!
	var bgView: UIView!
	
	var leftBtn: UIButton!
	
    override func viewDidLoad() {
        super.viewDidLoad()
		
		self.bgView = UIView()
		bgView.frame = self.view.bounds
		bgView.backgroundColor = UIColor.rgb("efefef", alpha: 0.5)
		self.view.addSubview(bgView)

		self.view.backgroundColor = UIColor.rgb("efefef", alpha: 0.5)
		
		
//		let btn1 = UIButton("fade", 100, 30, target: self, action: #selector(btn1Click))
//		self.view.addSubview(btn1)
		let btn2 = UIButton("cube", 140, 30, target: self, action: #selector(btn2Click))
		bgView.addSubview(btn2)
		let btn3 = UIButton("oglFlip", 180, 30, target: self, action: #selector(btn3Click))
		self.view.addSubview(btn3)
		let btn4 = UIButton("suckEffect", 220, 30, target: self, action: #selector(btn4Click))
		bgView.addSubview(btn4)
		let btn5 = UIButton("pageCurl", 260, 30, target: self, action: #selector(btn5Click))
		bgView.addSubview(btn5)
		let btn6 = UIButton("cameraIrisHollowOpen", 300, 30, target: self, action: #selector(btn6Click))
		self.view.addSubview(btn6)
		let btn7 = UIButton("cameraIrisHollowClose", 340, 30, target: self, action: #selector(btn7Click))
		self.view.addSubview(btn7)
		let btn8 = UIButton("rippleEffect", 380, 30, target: self, action: #selector(btn8Click))
		self.view.addSubview(btn8)
		
		let btn9 = UIButton("test", 380, 30, target: self, action: #selector(btn9Click))
		btn9.frame = CGRect(x: 10, y: 340, width: 50, height: 50)
		btn9.backgroundColor = UIColor.rgb("84a740")
		self.view.addSubview(btn9)
		leftBtn = btn9
    }
	
	func btn1Click() {
		let anim = CATransition()
		anim.type = "fade"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	func btn2Click() {
		let anim = CATransition()
		anim.type = "cube"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	
	func btn3Click() {
		let anim = CATransition()
		anim.type = "oglFlip"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	
	func btn4Click() {
		let anim = CATransition()
		anim.type = "suckEffect"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.bgView.layer.add(anim, forKey: nil)
		
	}
	
	
	func btn5Click() {
		let anim = CATransition()
		anim.type = "pageCurl"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.bgView.layer.add(anim, forKey: nil)
		
		UIView.animate(withDuration: 1, delay: 0, options: .curveEaseInOut, animations: {
			self.leftBtn.frame = CGRect(x: 300, y: 300, width: 50, height: 50)
		}) { (finish) in
			
		}
		
	}
	
	
	func btn6Click() {
		let anim = CATransition()
		anim.type = "cameraIrisHollowOpen"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	
	func btn7Click() {
		let anim = CATransition()
		anim.type = "cameraIrisHollowClose"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	func btn8Click() {
		let anim = CATransition()
		anim.type = "rippleEffect"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.view.layer.add(anim, forKey: nil)
	}
	
	
	func btn9Click() {
		let anim = CATransition()
		anim.type = "pageUnCurl"
		anim.duration = 1.0
		anim.subtype = kCATransitionFromLeft
		self.bgView.layer.add(anim, forKey: nil)
		
		UIView.animate(withDuration: 1, delay: 0, options: .curveEaseInOut, animations: {
			self.leftBtn.frame = CGRect(x: 10, y: 340, width: 50, height: 50)
		}) { (finish) in
			
		}
		
	}
	
	
	
	
	
	
}
